*****************************************************************************************************************************************************
* PROJECT: 		Exposure to the COVID-19 Stock Market Crash and its Effect on Household Expectations
* DATE: 		Nov 2020
* CONTENT: 		FIGURES
* AUTHORS: 		Tobin Hanspal, Johannes Wohlfart, Anni Weber
*****************************************************************************************************************************************************

		clear all
		set scheme lean2
		global pm = char(177)
		set more off
		gl date = c(current_date)
		graph set window fontface "cmr10"
		
		
* set cd as /Replication_files_HanspalWeberWohlfart2020/

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~						
** FIGURE A19
*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~	

use data/processed/data_1, clear

gen riskshare_retirwealth_Jan201=riskshare_retirwealth_Jan20
gen riskshare_ofinwealth_Jan201=riskshare_ofinwealth_Jan20
replace riskshare_retirwealth_Jan201=0 if retirJan20_0==1
replace riskshare_ofinwealth_Jan201=0 if ofinJan20_0==1
gen stockinvestor_retire=riskshare_retirwealth_Jan201>0 if riskshare_retirwealth_Jan201!=.
gen stockinvestor_ofin=riskshare_ofinwealth_Jan201>0 if riskshare_ofinwealth_Jan201!=.
gen delhhnetinc_USD_tr02alt_qtr_cond = delhhnetinc_USD_tr02alt_qtr if jobloss_20q1==1
gen del_hhnetinc_perc_tr02_cond = del_hhnetinc_perc_tr02 if jobloss_20q1==1
	
* Scale USD variables	
	foreach x in  delofin_USD_tr02 delretir_USD_tr02  delfinwealth_USD_tr02   delhhnetinc_USD_tr02 {
		replace `x' = `x'/1000
	}
	foreach x in ofinwealth_lvl retirewealth_lvl  finwealth_Jan20 hhinc_lvl hhnetinc_2019   {
		replace `x' = `x'/1000
	}

* gen conditional variables:
	gen del_ofin_perc_tr02_cond = del_ofin_perc_tr02
	replace del_ofin_perc_tr02_cond = . if stockinvestor_ofin!=1
	gen del_retir_perc_tr02_cond = del_retir_perc_tr02
	replace del_retir_perc_tr02_cond = . if stockinvestor_retire!=1
	gen del_finwealth_perc_tr02_cond = del_finwealth_perc_tr02
	replace del_finwealth_perc_tr02_cond = . if stockowner!=1

	gen delofin_USD_tr02_cond = delofin_USD_tr02
	replace delofin_USD_tr02_cond = . if stockinvestor_ofin!=1
	gen delretir_USD_tr02_cond = delretir_USD_tr02
	replace delretir_USD_tr02_cond = . if stockinvestor_retire!=1
	gen delfinwealth_USD_tr02_cond = delfinwealth_USD_tr02
	replace delfinwealth_USD_tr02_cond = . if stockowner!=1
	
* gen extensive margin vars:
	gen del_ofin_d = (del_ofin_perc_tr02<0) if  del_ofin_perc_tr02!=. 
	replace del_ofin_d = . if stockinvestor_ofin!=1

	gen del_retire_d = (del_retir_perc_tr02<0) if  del_retir_perc_tr02!=. 
	replace del_retire_d = . if stockinvestor_retire!=1

	gen del_finwealth_d = (del_finwealth_perc_tr02<0) if  del_finwealth_perc_tr02!=. 
	replace del_finwealth_d = . if stockowner!=1

	gen riskshare_5 = .
	replace riskshare_5=1 if riskshare_finwealth_Jan201>=0 &riskshare_finwealth_Jan201<=20 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=2 if riskshare_finwealth_Jan201>20 &riskshare_finwealth_Jan201<=40 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=3 if riskshare_finwealth_Jan201>40 &riskshare_finwealth_Jan201<=60 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=4 if riskshare_finwealth_Jan201>60 &riskshare_finwealth_Jan201<=80 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=5 if riskshare_finwealth_Jan201>80 &riskshare_finwealth_Jan201<=100 & riskshare_finwealth_Jan201!=.

	gen stockinvestor100 = stockinvestor*100
	gen stockinvestor_retire100 = (riskshare_retirwealth_Jan201>0 & riskshare_retirwealth_Jan201!=.)*100
	gen stockinvestor_ofin100 = (riskshare_ofinwealth_Jan201>0 & riskshare_retirwealth_Jan201!=.)*100

	* change in fin wealth by netwealth
	graph bar (mean) stockinvestor_ofin100 stockinvestor_retire100 stockinvestor100 , ///
		over(netwealth_Jan20_grp, relabel(1 1 2 2 3 3 4 4 5 5)) b1title(Net wealth quintile, size(medsmall)) ///
		  bargap(0)  /// 
		ytitle("Participation (%)", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(, nogrid)  legend(size(small) symxsize(3) symysize(3)  pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp1.gph, replace)
		
	*change in fin wealth by age
	graph bar (mean)  stockinvestor_ofin100 stockinvestor_retire100 stockinvestor100 , ///
		over(agecat, relabel(1 "18-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+") label(labsize(small))) b1title(Age group, size(medsmall)) ///
		  bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(20)100, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp2.gph, replace)
			
  * change in fin wealth by net income
	graph bar (mean) stockinvestor_ofin100 stockinvestor_retire100 stockinvestor100 , ///
		over(hhnetinc_2019_grp)  b1title(Net income quintile, size(medsmall)) ///
		  bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(20)100, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp3.gph, replace)
		
  * change in fin wealth by netwealth
	graph bar (mean) riskshare_ofinwealth_Jan20 riskshare_retirwealth_Jan20  riskshare_finwealth_Jan20 , ///
		over(netwealth_Jan20_grp, relabel(1 1 2 2 3 3 4 4 5 5)) b1title(Net wealth quintile, size(medsmall)) ///
		  bargap(0)  /// 
		ytitle("Risky share (%)" "Unconditional", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(20)60, nogrid)  legend(size(small) symxsize(3) symysize(3)  pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp1a.gph, replace)
		
	*change in fin wealth by age
	graph bar (mean)  riskshare_ofinwealth_Jan20 riskshare_retirwealth_Jan20  riskshare_finwealth_Jan20 , ///
		over(agecat, relabel(1 "18-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+") label(labsize(small))) b1title(Age group, size(medsmall)) ///
		  bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(20)60, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp2a.gph, replace)
			
  * change in fin wealth by net income
	graph bar (mean)riskshare_ofinwealth_Jan20 riskshare_retirwealth_Jan20  riskshare_finwealth_Jan20 , ///
		over(hhnetinc_2019_grp)  b1title(Net income quintile, size(medsmall)) ///
		  bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(20)60, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp3a.gph, replace)
		
*conditional 
keep if stockinvestor==1

  * change in fin wealth by netwealth
	graph bar (mean) riskshare_ofinwealth_Jan20 riskshare_retirwealth_Jan20  riskshare_finwealth_Jan20 , ///
		over(netwealth_Jan20_grp, relabel(1 1 2 2 3 3 4 4 5 5)) b1title(Net wealth quintile, size(medsmall)) ///
		  bargap(0)  /// 
		ytitle("Risky share (%)" "Conditional", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(20)60, nogrid)  legend(size(small) symxsize(3) symysize(3)  pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp1b.gph, replace)

	*change in fin wealth by age
	graph bar (mean)  riskshare_ofinwealth_Jan20 riskshare_retirwealth_Jan20  riskshare_finwealth_Jan20 , ///
		over(agecat, relabel(1 "18-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+") label(labsize(small))) b1title(Age group, size(medsmall)) ///
		  bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(20)60, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp2b.gph, replace)
	
  * change in fin wealth by net income
	graph bar (mean)riskshare_ofinwealth_Jan20 riskshare_retirwealth_Jan20  riskshare_finwealth_Jan20 , ///
		over(hhnetinc_2019_grp)  b1title(Net income quintile, size(medsmall)) ///
		  bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(0(20)60, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp3b.gph, replace)
		
	grc1leg2 	Figures/temp1.gph ///
					Figures/temp3.gph ///
					Figures/temp2.gph ///
					Figures/temp1a.gph ///
					Figures/temp3a.gph ///
					Figures/temp2a.gph ///
					Figures/temp1b.gph ///
					Figures/temp3b.gph ///
					Figures/temp2b.gph ///
					, cols(3) rows(3) ysize(3) xsize(5) ///
					ring(1) pos(6)  legendfrom(Figures/temp1.gph) lsize(vsmall) xcommon iscale(0.6)
					
	graph export Figures/FigureA19.pdf, as(pdf)  fontface("cmr10") replace	
	graph export Figures/FigureA19.png, width(1600) replace 
	
forvalues x = 1/3 {
		capture erase Figures/temp`x'.gph
		capture erase Figures/temp`x'a.gph
		capture erase Figures/temp`x'b.gph
}						
						
